home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9145 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: passing arguments to main()
  5. Date: Wed, 06 Mar 96 22:07:47 GMT
  6. Organization: none
  7. Message-ID: <826150067snz@genesis.demon.co.uk>
  8. References: <4h78t1$nqq@netnews.upenn.edu> <4h7ql8$4rs@news.microsoft.com> <4hiqms$kg2@mother.usf.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4hiqms$kg2@mother.usf.edu> sanidas "BIO" writes:
  15.  
  16. >I'm not sure I understand your question.  I think you may want to look at the
  17. >two variables argc and argv.  Declared like this: 
  18. >main(int argc, char* argv[])
  19. >{
  20. >/*C code here*/
  21. >
  22. >return;
  23. >}
  24. >
  25. >argc is an integer that counts the number of commands on the command line
  26.  
  27. I assume you mean the number of command line arguments. A program is
  28. generally invoked by a single command.
  29.  
  30. > (it
  31. >is always at least one because the executable file name counts as a command).
  32.  
  33. The program name is counted in argc. However the C language allows argc
  34. to be 0 where there is neither a program name nor any command line arguments
  35. available. A partable C program will not assume that argc is nonzero.
  36.  
  37. >argv is an array of pointers that point to a character array.
  38.  
  39. argv is a pointer to the first element of an array of char * pointers.
  40. Each char * pointer points to the first element of an array of char whose
  41. contents is a string (i.e. a sequence of characters ending in the null
  42. character). The last pointer in the array of char * (i.e. argv[argc]) is a
  43. null pointer.
  44.  
  45. -- 
  46. -----------------------------------------
  47. Lawrence Kirby | fred@genesis.demon.co.uk
  48. Wilts, England | 70734.126@compuserve.com
  49. -----------------------------------------
  50.